class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> hash;
        for (string& s : strs) {
            string sorted = s;
            sort(sorted.begin(),sorted.end());
            hash[sorted].push_back(s);
        }

        vector<vector<string>> ans;
        ans.reserve(hash.size());
        for(auto it= hash.begin();it!=hash.end();it++)
        {
            ans.push_back(it->second);
        }
        return ans;
    }
};
